package com.bloveoacom.weichi.activity;

import android.app.Dialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bloveoacom.base.AppContext;
import com.bloveoacom.base.BaseActivity;
import com.bloveoacom.util.DialogUtil;
import com.bloveoacom.util.PicCameraLocalUtil;
import com.bloveoacom.util.ShareUtils;
import com.bloveoacom.util.ToastUtil;
import com.bloveoacom.weichi.R;
import com.bloveoacom.weight.LlkjToolBar;

import java.io.File;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * author: yjl
 * e-mail: 1271901673@qq.com
 * time  : 2018/9/21
 * desc  :
 */
public class ShareActivity extends BaseActivity {
    @BindView(R.id.title_bar)
    LlkjToolBar mToolbar;
    @BindView(R.id.layout_share)
    View layoutShare;

    @Override
    public int getLayoutResId() {
        return R.layout.activity_share;
    }

    @Override
    protected View getViewSetTB() {
        return mToolbar;
    }

    @Override
    public void initView() {
        mToolbar.setToolBar("邀请好友",
                true, "", R.drawable.ic_back, false, "", LlkjToolBar.isNull);

    }

    @Override
    public void initData() {

    }

    @Override
    public void getBundleExtras(Bundle extras) {

    }

    @Override
    public void initListener() {

    }
    @OnClick(R.id.btn_share)
    public void onViewClicked() {
        share();
    }

    private Bitmap shareBitmap;
    private File sharefile;
    private Dialog dialog;
    private void share() {
        if(shareBitmap==null){
            shareBitmap = PicCameraLocalUtil.getBitmap(layoutShare);
        }
        if (dialog == null || sharefile == null) {
            sharefile = PicCameraLocalUtil.saveBitmap(mContext,shareBitmap,"invite_friend");
            AppContext.mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    dialog = DialogUtil.getPicBottomDialog2(mContext, new DialogUtil.PhotoDoWhat() {
                        @Override
                        public void doone() {
                            ShareUtils.shareFriends(sharefile.getPath(), 0);
                            DialogUtil.dissDialog(dialog);
                            ToastUtil.makeShortText(mContext, "分享操作正在后台进行");
                        }

                        @Override
                        public void dotwo() {
                            ShareUtils.shareFriends(sharefile.getPath(), 1);
                            DialogUtil.dissDialog(dialog);
                            ToastUtil.makeShortText(mContext, "分享操作正在后台进行");
                        }
                        @Override
                        public void dothree() {
                            DialogUtil.dissDialog(dialog);
                        }
                    }, sharefile);
                    DialogUtil.showDialog(dialog);
                }
            }, 1000);

        } else {
            DialogUtil.showDialog(dialog);
        }
    }
}
